/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modlemgooglesvn.modlem_src;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collections;

/**
 *
 * @author xXx
 */
public class OdczytPlikuBinarnego {
    
      public static String input = 
                //"D:\\ZBIORY_DANYCH\\data\\irysy.tab",
                
               "D:\\ZBIORY_DANYCH\\kddcup_test15.txt",
//                   "D:\\ZBIORY_DANYCH\\kddcup_train.txt", 
//    protected static String input = "M:\\kddcup_train.txt",
           output = "C:\\wynik.bin0246";
      
     // output = "C:\\plik 0.bin";
   static String parametry = "C:\\wynik.bin_parametry_bazy.bin";
         public static void main(String[] args) throws IOException {
         String coRozdzielaDane = ",";
         KonwersjaBinarna kb = new KonwersjaBinarna();
         
// kb.konwersjaBazy(input,output,coRozdzielaDane);
        // kb.odczytPlikuBinarnego(output);
         OdczytPlikuBinarnego.OdczytBinarny(output, parametry);
       
    }  
    
       public static void OdczytBinarny(String input,String wynikParametry)
            throws FileNotFoundException, IOException {
                  

        long poczatek = System.currentTimeMillis();;

        RandomAccessFile raf = new RandomAccessFile(input, "r");

        FileDescriptor fd = raf.getFD();
        FileInputStream fis = new FileInputStream(fd);
        BufferedInputStream bis = new BufferedInputStream(fis);
        DataInputStream dis = new DataInputStream(bis);

//
        FileReader fr = new FileReader(wynikParametry);
        
        BufferedReader bf = new BufferedReader(fr);
//                new BufferedReader(new InputStreamReader(
//                new FileInputStream(wynikParametry)));
        
        int ileAtrybutow = Integer.parseInt(bf.readLine());
        int[] typAtrybutow = new int[ileAtrybutow];
        for (int i = 0; i < ileAtrybutow; i++) {
            typAtrybutow[i] = Integer.parseInt(bf.readLine());
        }




        int ktoryAtrybut = 41;
        ArrayList<String> atrybutStatystyka = new ArrayList();
       
        int i = 0;
        int g = 0;

        while (true) {
double dod = 
   -9999999999999999999999999999999999999999999999999999999999999999123456789.9;
int intt = -1234567899;
String stt = "12345678987654321";
            try {

                
                if(typAtrybutow[i]==1){
                System.out.print(dis.readInt()+","); 
                }
                else if(typAtrybutow[i]==2){
                    System.out.print(dis.readDouble()+",");
                }
                else if(typAtrybutow[i]==3){
                    System.out.print(dis.readUTF());
                    if(i==ileAtrybutow-1)System.out.println();
                    else
                    System.out.print(",");
                }
                else System.out.print("Jakis error w metodaOdczytu");
                
//


          i++;

                if (i == ileAtrybutow) {

                    i = 0;
                 
//
//
                         g++;
//
                }
                
                
                      
            } catch (EOFException e) {
                break;
            }

        }
        long srodek =
                System.currentTimeMillis();

        Collections.sort(atrybutStatystyka);

        long koniec = System.currentTimeMillis();
        System.out.println("Program doszedl do polowy po "
                + (srodek - poczatek) + ", posortowanie zajelo \n"
                + (koniec - srodek) + " ,a calosc trwala "
                + (koniec - poczatek) + " ,ilosc wartosci w atrybucie "
                + atrybutStatystyka.size());
      

//        int j = 0;
//        while (true) {
//            System.out.println(atrybutStatystyka.get(j));
//            j++;
//        }

    }
 
    
}
